package ex;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-7下午 05:49
 */
public class preorderTree {
    static class TreeNode {
        TreeNode left;
        TreeNode right;
        int value = 0;

        public TreeNode(int i) {
            this.value = i;
        }
    }

    static List<Integer> list = new ArrayList<>();

    public static List<Integer> pre(TreeNode root) {
        if (root == null) {
            return list;
        }
        list.add(root.value);
        pre(root.left);
        pre(root.right);
        return list;
    }

    public static void main(String[] args) {
        final TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        pre(root);
        System.out.println(list.toString());
    }
}
